package com.vexelcorp.simpleFragment;


import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class SimpleFragmentActivity extends FragmentActivity {
	  
    private static final String DEBUG_TAG = "DEBUG_TAG";
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        //Create ImageViewFragment and put in r.id.framelayout2
        
        //Create new instance
        ImageViewFrag frag = ImageViewFrag.newInstance(0);
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        
        //replace
        ft.replace(R.id.frameLayout2, frag);
        
        //commit
        ft.commit();
        
    }
    
    
    public static class FoodListFragment extends ListFragment{
    	


		@Override
		public void onActivityCreated(Bundle savedInstanceState) {
			// TODO Auto-generated method stub
			super.onActivityCreated(savedInstanceState);
			
			getListView();
			String[] food_list = getResources().getStringArray(R.array.food_array);
			
			ArrayAdapter<String> foodArrayAdapter = new ArrayAdapter<String>(getActivity(),
					android.R.layout.simple_list_item_1, food_list);
			setListAdapter(foodArrayAdapter);
		}

		@Override
		public void onListItemClick(ListView l, View v, int position, long id) {
			// TODO Auto-generated method stub
			Log.d(DEBUG_TAG, "inside onListItemClick");
			
			super.onListItemClick(l, v, position, id);
			
			int currentPosition = position;
			
			//Create new instance of fragment
			ImageViewFrag imageViewFrag = ImageViewFrag.newInstance(currentPosition);
			
		 
			//Initiate transaction
			FragmentTransaction ft = getFragmentManager().beginTransaction();
			
			//set custom animations. MUST be before replace
			ft.setCustomAnimations(android.R.anim.slide_in_left,android.R.anim.slide_out_right);
			
			//.replace(frame ID, fragment object)
			ft.replace(R.id.frameLayout2, imageViewFrag);
			
		
			ft.commit();
			
			
		}
		
		
    	
    }
    
 
    
}